package c1764;

import java.util.Scanner;

public class H {
    static char[] s1 = {'H', 'C', 'N', 'O', 'F', 'P', 'S', 'K'};
    static int[] s2 = {1, 12, 14, 16, 19, 31, 32, 39};

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        while (n-- > 0) {
            String s = cin.next();
            int temp = 0, sum = 0;
            for (int i = 0; i < s.length() - 1; i++)
                for (int j = 0; j < 8; j++) {
                    if (s.charAt(i) == s1[j] && Character.isDigit(s.charAt(i + 1))) {
                        temp = s2[j];
                        temp *= (Integer.valueOf((s.substring(i + 1, i + 2))));
                        //temp*=(s.charAt(i+1)-'0');
                        i++;
                        sum += temp;
                        break;
                    } else if (s.charAt(i) == s1[j] && Character.isLetter(s.charAt(i + 1))) {
                        temp = s2[j];
                        sum += temp;
                        break;
                    }
                }
            if (Character.isLetter(s.charAt(s.length() - 1))) {
                for (int k = 0; k < 8; k++) {
                    if (s.charAt(s.length() - 1) == s1[k]) {
                        temp = s2[k];
                        sum += temp;
                        break;
                    }
                }
            }
            System.out.println(sum);
        }
    }
}